package Thread.Test.Test2;

import java.util.concurrent.Callable;

public class MyCallable implements Callable<String> {

    public static int gifts = 100;

    public Object obj = new Object();

    @Override
    public String call() throws Exception {

        while (true) {
            synchronized (obj) {
                if (gifts < 10) {
                    break;
                } else {
                    //没有小于10
                    gifts--;
                    System.out.println(Thread.currentThread().getName() + "同学发送了1个礼品,还剩" + gifts + "个");
                }
            }
        }
        return null;
    }
}
